import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { PartialConsult, Illness } from '@/types/consult'
import type { ConsultType } from '@/enums'

/**
 * 参数1：仓库的名字（调试工具中可以看到）
 * 参数2：回调函数（里面写上仓库的逻辑）
 * 参数3：持久化
 */
export const useConsultStore = defineStore(
  'cp-consult',
  () => {
    // 定义问诊数据模型（这个数据就是下单所需的数据）
    const consult = ref<PartialConsult>({})

    // 保存类型的方法
    const setType = (type: ConsultType) => {
      consult.value.type = type
    }

    // 设置急速问诊的类型
    const setIllnessType = (type: 0 | 1) => {
      consult.value.illnessType = type
    }

    // 设置科室
    const setDepId = (depId: string) => {
      consult.value.depId = depId
    }

    // 设置图文问诊
    const setIllness = (illness: Illness) => {
      consult.value.illnessDesc = illness.illnessDesc
      consult.value.illnessTime = illness.illnessTime
      consult.value.consultFlag = illness.consultFlag
      consult.value.pictures = illness.pictures
    }

    // 设置患者Id
    const setPatientId = (patientId: string) => {
      consult.value.patientId = patientId
    }

    // 设置优惠券id
    const setCouponId = (couponId: string) => {
      consult.value.couponId = couponId
    }

    // 清空consult
    const clear = () => {
      consult.value = {}
    }

    return {
      consult,
      setType,
      setIllnessType,
      setDepId,
      setIllness,
      setPatientId,
      setCouponId,
      clear
    }
  },
  {
    persist: true
  }
)
